/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Presentation;

import BLO.DoibongBLO;
import BLO.LichTDBLO;
import BLO.SanBLO;
import BLO.TrongtaiBLO;
import DAO.ResultsModel;
import DTO.*;
import com.toedter.calendar.JDateChooser;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
 *
 * @author LUCKYSTARS
 */
public class LichThiDau extends javax.swing.JPanel {

class SelectionListener implements ListSelectionListener {
    JTable table;
    SelectionListener(JTable table) {
    this.table = table;}
    public void valueChanged(ListSelectionEvent e) {
          int row= table.getSelectedRow();
          if(row>=0)
          {
           cmbVong.setSelectedItem(Integer.parseInt(table.getValueAt(row, 0).toString().trim()));
           cmbTran.setSelectedItem(Integer.parseInt(table.getValueAt(row, 1).toString().trim()));
           cmbDoinha.setSelectedItem(table.getValueAt(row, 3).toString().trim());
           cmbDoikhach.setSelectedItem(table.getValueAt(row, 4).toString().trim());
           cmbSan.setSelectedItem(table.getValueAt(row, 7).toString().trim());
           cmbTrongtaichinh.setSelectedItem(table.getValueAt(row,8).toString().trim());
           
           String tgian=table.getValueAt(row,6).toString().trim();
           int gio=Integer.parseInt(tgian.substring(0, 2));
           int phut=Integer.parseInt(tgian.substring(3, 5));
            cmbGio.setSelectedItem(gio);
            cmbPhut.setSelectedItem(phut);
            
            txtMatrandau.setText(table.getValueAt(row,2).toString().trim());
            
           //JOptionPane.showMessageDialog(null,gio);
          // cmbGio.setSelectedItem(table.getValueAt(row, 5).toString().trim());

          }
    }
  }     
    
    DoibongBLO dbBLO= new DoibongBLO();
    SanBLO sBLO= new SanBLO();
    TrongtaiBLO ttBLO= new TrongtaiBLO();
    LichTDBLO ltdBLO= new LichTDBLO();
    
    public LichThiDau() {
        initComponents();
        dtpNgaythidau.setDateFormatString("MM/dd/yyyy");
        ResultSet dtDoibong=dbBLO.Getdata1();
        int sodoibong=0;
        try {
            //Add du lieu vao cmb Doi nha va cmb Doi khach
            while (dtDoibong.next()) 
            {
                cmbDoinha.addItem(dtDoibong.getString("Ten_db"));
                cmbDoikhach.addItem(dtDoibong.getString("Ten_db"));
                sodoibong++;
            }
            //Add du lieu vao so vong va so tran
            for(int i=1;i<(sodoibong-1)*2+1;i++)
                cmbVong.addItem(i);
            for(int i=1;i<sodoibong/2 +1;i++)
                cmbTran.addItem(i);
            //Add gio phut giay vao cmb
            for(int i=0;i<24;i++)
                cmbGio.addItem(i);
            for(int i=0;i<60;i++)
            {
                cmbPhut.addItem(i);
            }
            //Add du lieu vao cmb San
              ResultSet dtSan=sBLO.Getdata();
              while(dtSan.next())
              {
                  cmbSan.addItem(dtSan.getString("ten_san"));
              }
              //Add du lieu vao Cmb Trongtai
              ResultSet dtTrongtai= ttBLO.Getdata();
               
              while(dtTrongtai.next())
              {
                 cmbTrongtaichinh.addItem(dtTrongtai.getString("Ho_ten"));
                 cmbTrongtaibien1.addItem(dtTrongtai.getString("Ho_ten"));
                 cmbTrongtaibien2.addItem(dtTrongtai.getString("Ho_ten"));
                 cmbTrongtaiban.addItem(dtTrongtai.getString("Ho_ten"));
              }
            //Load du lieu len JTable
            ResultsModel dtable= ltdBLO.Getdata();
            JTable tb= new JTable(dtable);
            tb.setBounds(0,0,869,200);
            JScrollPane js= new JScrollPane(tb);
            js.setBounds(0,0,869,200);
            jtableXeplich.removeAll();
            jtableXeplich.add(js);
            
            
                SelectionListener listener = new SelectionListener(tb);
              tb.getSelectionModel().addListSelectionListener(listener);
        } catch (SQLException ex) {
             JOptionPane.showMessageDialog(null,ex.getMessage() );
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        cmbVong = new javax.swing.JComboBox();
        cmbTran = new javax.swing.JComboBox();
        cmbDoinha = new javax.swing.JComboBox();
        cmbDoikhach = new javax.swing.JComboBox();
        cmbSan = new javax.swing.JComboBox();
        dtpNgaythidau = new com.toedter.calendar.JDateChooser();
        cmbGio = new javax.swing.JComboBox();
        cmbPhut = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        cmbTrongtaichinh = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        cmbTrongtaibien1 = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        cmbTrongtaibien2 = new javax.swing.JComboBox();
        cmbTrongtaiban = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtMatrandau = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        btnThem = new javax.swing.JButton();
        btnXoa = new javax.swing.JButton();
        btnTrove = new javax.swing.JButton();
        jtableXeplich = new javax.swing.JPanel();

        setMaximumSize(new java.awt.Dimension(869, 533));
        setMinimumSize(new java.awt.Dimension(869, 533));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jLabel1.setText("XẾP LỊCH THI ĐẤU");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setEnabled(false);

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel2.setText("Vòng:");

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel3.setText("Trận:");

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel4.setText("Đội nhà:");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel5.setText("Đội khách:");

        jLabel7.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel7.setText("Ngày thi đấu:");

        jLabel8.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel8.setText("Giờ thi đấu:");

        jLabel9.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel9.setText("Sân:");

        dtpNgaythidau.setDateFormatString("MM/dd/yyyy");

        jLabel14.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel14.setText("Giờ");

        jLabel15.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel15.setText("Phút");

        jLabel10.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel10.setText("Trọng tài chính:");

        jLabel11.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel11.setText("Trọng tài biên 1:");

        jLabel12.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel12.setText("Trọng tài biên 2:");

        jLabel13.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel13.setText("Trọng tài bàn:");

        jLabel6.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
        jLabel6.setText("Mã trận đấu:");

        txtMatrandau.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(46, 46, 46)
                        .addComponent(cmbVong, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(cmbTran, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(dtpNgaythidau, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(32, 32, 32)
                                .addComponent(cmbDoinha, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(69, 69, 69)
                                        .addComponent(jLabel14))
                                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(txtMatrandau))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addGap(18, 18, 18)
                                        .addComponent(cmbDoikhach, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(24, 24, 24)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cmbSan, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(cmbGio, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cmbPhut, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cmbTrongtaiban, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(cmbTrongtaichinh, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(18, 18, 18))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addGap(18, 18, 18)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cmbTrongtaibien2, 0, 162, Short.MAX_VALUE)
                            .addComponent(cmbTrongtaibien1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dtpNgaythidau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(cmbVong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cmbTran, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7)
                                .addComponent(jLabel2)))
                        .addGap(27, 27, 27)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cmbGio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cmbPhut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel15)
                                .addComponent(jLabel14)
                                .addComponent(jLabel8)
                                .addComponent(jLabel11)
                                .addComponent(cmbTrongtaibien1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4)
                                .addComponent(cmbDoinha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cmbSan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel12)
                                .addComponent(cmbTrongtaibien2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(cmbDoikhach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel9))))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(cmbTrongtaichinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(cmbTrongtaiban, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtMatrandau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnThem.setText("Thêm");
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });

        btnXoa.setText("Xóa");
        btnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaActionPerformed(evt);
            }
        });

        btnTrove.setText("Trở về");
        btnTrove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTroveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnThem, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnTrove, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnThem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnTrove, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                    .addComponent(btnXoa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jtableXeplich.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jtableXeplichLayout = new javax.swing.GroupLayout(jtableXeplich);
        jtableXeplich.setLayout(jtableXeplichLayout);
        jtableXeplichLayout.setHorizontalGroup(
            jtableXeplichLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 868, Short.MAX_VALUE)
        );
        jtableXeplichLayout.setVerticalGroup(
            jtableXeplichLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 166, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(290, 290, 290))
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jtableXeplich, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtableXeplich, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed
    try {
        LICHTD lDTO= new LICHTD();
        TRANDAU tdDTO= new TRANDAU();
        DOIBONG dbDoiNha= new DOIBONG();
        DOIBONG dbDOikhach= new DOIBONG();
        SAN sDTO= new SAN();
        TRONGTAI ttChinh= new TRONGTAI();
        TRONGTAI ttBien1= new TRONGTAI();
        TRONGTAI ttBien2= new TRONGTAI();
        TRONGTAI ttBan= new TRONGTAI();
        NGUOI ng1= new NGUOI();
        NGUOI ng2= new NGUOI();
        NGUOI ng3= new NGUOI();
        NGUOI ng4= new NGUOI();
        
        if(cmbGio.getSelectedItem()==0)
              JOptionPane.showMessageDialog(null,"Chưa chọn giờ thi đấu!","Thong bao",JOptionPane.INFORMATION_MESSAGE);
        else if( dtpNgaythidau.getDate().toString().trim().length()==0)
                JOptionPane.showMessageDialog(null,"Chưa chọn  ngày thi đấu!","Thong bao",JOptionPane.INFORMATION_MESSAGE);
        else
        {
        lDTO.setSovong(Integer.parseInt(cmbVong.getSelectedItem().toString().trim()));
        lDTO.setSotran(Integer.parseInt(cmbTran.getSelectedItem().toString().trim()));
        
        Time giodau= new Time(Integer.parseInt(cmbGio.getSelectedItem().toString()),Integer.parseInt(cmbPhut.getSelectedItem().toString()),0);
       
        
        dbDoiNha.setTenDB(cmbDoinha.getSelectedItem().toString());
        dbDoiNha.setMaDB(dbBLO.GetMaFTenDoibong(dbDoiNha));
        
        dbDOikhach.setTenDB(cmbDoikhach.getSelectedItem().toString());
        dbDOikhach.setMaDB(dbBLO.GetMaFTenDoibong(dbDOikhach));
        
        sDTO.setTensan(cmbSan.getSelectedItem().toString());
        sDTO.setMasan(sBLO.GetMasanFTensan(sDTO));
        
        ng1.setHoten(cmbTrongtaichinh.getSelectedItem().toString());
        ng1.setManguoi(ttBLO.GetMaFTenTrongTai(ng1));
        ttChinh.setNguoi(ng1);
        
        ng2.setHoten(cmbTrongtaibien1.getSelectedItem().toString());
        ng2.setManguoi(ttBLO.GetMaFTenTrongTai(ng2));
        ttBien1.setNguoi(ng2);
        
        ng3.setHoten(cmbTrongtaibien2.getSelectedItem().toString());
        ng3.setManguoi(ttBLO.GetMaFTenTrongTai(ng3));
        ttBien2.setNguoi(ng3);
        
        ng4.setHoten(cmbTrongtaiban.getSelectedItem().toString());
        ng4.setManguoi(ttBLO.GetMaFTenTrongTai(ng4));
        ttBan.setNguoi(ng4);
        
        tdDTO.setDoichu(dbDoiNha);
        tdDTO.setDoikhach(dbDOikhach);
        tdDTO.setGiodau(giodau);
       
        dtpNgaythidau.setDateFormatString("MM/dd/yyyy");
        Calendar cal = dtpNgaythidau.getCalendar();
        int datevar= cal.get(Calendar.DATE);
        int monthvar = cal.get(Calendar.MONTH);
        int yearvar = cal.get(Calendar.YEAR)-1900;
        Date d= new Date(yearvar, monthvar, datevar);
        tdDTO.setNgaydau(d);
        
        tdDTO.setSan(sDTO);
        tdDTO.setTtChinh(ttChinh);
        tdDTO.setTtBien1(ttBien1);
        tdDTO.setTtBien2(ttBien2);
        tdDTO.setTtBan(ttBan);
       
        tdDTO.setMatrandau(dbDoiNha.getMaDB().trim()+dbDOikhach.getMaDB().trim());
        lDTO.setTrandau(tdDTO);
        
  
        
        ltdBLO.Insert(lDTO);
        
           ResultsModel dtable= ltdBLO.Getdata();
            JTable tb= new JTable(dtable);
            tb.setBounds(0,0,869,200);
            JScrollPane js= new JScrollPane(tb);
            js.setBounds(0,0,869,200);
            jtableXeplich.removeAll();
            jtableXeplich.add(js);
        }
        
    }
    
    catch(Exception ex)
        {
           JOptionPane.showMessageDialog(null,ex.getMessage(),"Thong bao",JOptionPane.INFORMATION_MESSAGE);
        }
        
        
    //Su kien selection change    
   
        
        // TODO add your handling code here:
    }//GEN-LAST:event_btnThemActionPerformed

    private void btnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaActionPerformed
        try {
            LICHTD ltdDTOO = new LICHTD();
            TRANDAU tdDTO = new TRANDAU();
            tdDTO.setMatrandau(txtMatrandau.getText().toString().trim());
            ltdDTOO.setTrandau(tdDTO);
            ltdBLO.Delete(ltdDTOO);
            
            ResultsModel dtable = ltdBLO.Getdata();
            JTable tb = new JTable(dtable);
            tb.setBounds(0, 0, 869, 200);
            JScrollPane js = new JScrollPane(tb);
            js.setBounds(0, 0, 869, 200);
            jtableXeplich.removeAll();
            jtableXeplich.add(js);
            SelectionListener listener = new SelectionListener(tb);
            tb.getSelectionModel().addListSelectionListener(listener);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null,ex.getMessage(),"Thong bao",JOptionPane.INFORMATION_MESSAGE);
        }
        
        // TODO add your handling code here:
    }//GEN-LAST:event_btnXoaActionPerformed

    private void btnTroveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTroveActionPerformed

         this.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_btnTroveActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnThem;
    private javax.swing.JButton btnTrove;
    private javax.swing.JButton btnXoa;
    private javax.swing.JComboBox cmbDoikhach;
    private javax.swing.JComboBox cmbDoinha;
    private javax.swing.JComboBox cmbGio;
    private javax.swing.JComboBox cmbPhut;
    private javax.swing.JComboBox cmbSan;
    private javax.swing.JComboBox cmbTran;
    private javax.swing.JComboBox cmbTrongtaiban;
    private javax.swing.JComboBox cmbTrongtaibien1;
    private javax.swing.JComboBox cmbTrongtaibien2;
    private javax.swing.JComboBox cmbTrongtaichinh;
    private javax.swing.JComboBox cmbVong;
    public com.toedter.calendar.JDateChooser dtpNgaythidau;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jtableXeplich;
    private javax.swing.JTextField txtMatrandau;
    // End of variables declaration//GEN-END:variables
}
